package com.vf.admin.platform.controller;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.aliyun.oss.internal.OSSUtils;
import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
import com.vf.admin.client.common.RedisKeys;
import com.vf.admin.client.dao.AppMessageRecordDao;
import com.vf.admin.client.dao.AppSetupDao;
import com.vf.admin.client.service.*;
import com.vf.admin.common.BaseController;
import com.vf.admin.common.Constants;
import com.vf.admin.common.redis.RedisUtil;
import com.vf.admin.miaodong.entity.*;
import com.vf.admin.miaodong.service.*;
import com.vf.admin.platform.controller.dto.KeFuDto;
import com.vf.admin.platform.controller.dto.KeFuInfoDto;
import com.vf.admin.platform.entity.Menu;
import com.vf.admin.platform.entity.Role;
import com.vf.admin.platform.entity.User;
import com.vf.admin.platform.entity.UserRole;
import com.vf.admin.platform.service.RoleService;
import com.vf.admin.platform.service.UserRoleService;
import com.vf.admin.platform.service.UserService;
import com.vf.admin.utils.RecuUtils;
import com.vf.admin.utils.StringEx;
import org.apache.hadoop.mapred.IFile;
import org.omg.CORBA.PUBLIC_MEMBER;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static com.sun.tools.doclint.Entity.or;
import static com.sun.tools.doclint.Entity.quot;

@Controller
@RequestMapping("/web")
public class IndexController extends BaseController {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());
    @Resource
    RedisUtil redisUtil;
    @Autowired
    UserService userService;
    @Autowired
    UserRoleService userRoleService;
    @Autowired
    RoleService roleService;
    @Autowired
    AppUserService appUserService;
    @Autowired
    AppFollowService appFollowService;
    @Autowired
    AfterMingxiJinbiService afterMingxiJinbiService;
    @Autowired
    AppEarningsService earningsService;
    @Autowired
    AppMessageRecordDao messageRecordDao;
    @Autowired
    AfterSuggestService afterSuggestService;
    @Autowired
    private AppMingxiChongzhiService appMingxiChongzhiService;
    @Autowired
    private AppGiftRewardService appGiftRewardService;
    @Autowired
    private AppQianDaoRecordService appQianDaoRecordService;
    @Autowired
    private AppDynamicService appDynamicService;
    @Autowired
    private AppSuggestService appSuggestService;
    @Autowired
    private AppFeedbackRecordService appFeedbackService;
    @Autowired
    private AfterVipOrderService afterVipOrderService;
    @Autowired
    private AfterAppActiveService afterAppActiveService;
    @Autowired
    private AppMingXiShouLiService appMingXiShouLiService;
    @Autowired
    private AppMingXiZuanShiService appMingXiZuanShiService;
    @Autowired
    private AppMingxiJinbiService appMingxiJinbiService;
    @Autowired
    private AfterOrderService afterOrderService;

    @Autowired
    AppSetupDao appSetupDao;


    @RequestMapping("/index.html")
    public String validation() {
        Object headerObj = request.getHeader(Constants.access_token);
        if (StringEx.isNotNull(headerObj)) {
            Object tokenObj = redisUtil.get(headerObj.toString());
            if (StringEx.isNull(tokenObj)) {
                return "redirect:/web/main.html";
            }
        }
        return "/web/login";
    }

    /**
     * 获取当前登录用户的角色对应的菜单权限
     */
    @RequestMapping("/main.html")
    public String roleMenu() {
        try {
            List<Menu> menuList = new ArrayList<Menu>();

            User user = (User) request.getSession(false).getAttribute(Constants.access_token);
//            String token = request.getHeader(Constants.access_token);
//            Map<String, Object> resMap = new HashMap<String,Object>();
//            User user = (User)redisUtil.get(token);

            Map<String, Object> paramap = new HashMap<String, Object>();
            paramap.put("userid", user.getId());
            List<Menu> list = userRoleService.findMenuListByUserId(paramap);

            List<Menu> resultList = new ArrayList<Menu>();
            if (list != null && list.size() > 0) {
                for (Menu menu : list) {
                    resultList.add(menu);
                }
                menuList = RecuUtils.getInstance().findLeftMenuList(resultList, 1);
            }
            if (menuList != null) {
                menuList = menuList.stream().sorted(Comparator.comparing(Menu::getSorts).reversed()).collect(Collectors.toList());
            }
            request.setAttribute("menuList", menuList);
            return this.sucess("/web/main");
        } catch (Exception e) {
            logger.error("获取当前登录用户的角色对应的菜单权限", e);
            return this.error("获取信息失败，请联系管理员！");
        }
    }

//    /**
//     * 欢迎界面
//     *
//     * @return
//     */
//    @RequestMapping("/welcome.html")
//    public String welcome(String time) {
//
//        System.out.println("选择的时间：" + time);
//
//        //标题
//        SimpleDateFormat formatter = new SimpleDateFormat("yyyy年MM月dd日");
//        Date date = new Date();//得到当前系统时间
//        String str_date = formatter.format(date); //将日期时间格式化
//        String dayNames[] = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
//        Calendar calendar = Calendar.getInstance();
//        calendar.setTime(date);
//        int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
//        int hours = calendar.get(Calendar.HOUR_OF_DAY);
//
//        String str_hours = (hours > 12) ? "下午好" : "上午好";
//        if (hours < 6)
//            str_hours = "凌晨好";
//        else if (hours >= 6 && hours < 9)
//            str_hours = "早上好";
//        else if (hours >= 9 && hours < 12)
//            str_hours = "上午好";
//        else if (hours >= 12 && hours < 13)
//            str_hours = "中午好";
//        else if (hours >= 13 && hours < 18)
//            str_hours = "下午好";
//        else if (hours >= 18 && hours < 20)
//            str_hours = "晚上好";
//        else if (hours >= 21)
//            str_hours = "夜已深,请保重身体";
//
//        String str_week = dayNames[dayOfWeek - 1];
//        User user = (User) request.getSession(false).getAttribute(Constants.access_token);
//
//        //数据
//        Map<String, Object> stringObjectMap = indexData(time);
//
//        request.setAttribute("str_date", str_date);
//        request.setAttribute("str_hours", str_hours);
//        request.setAttribute("str_week", str_week);
//        request.setAttribute("user", user);
//        request.setAttribute("obj", stringObjectMap);
//        return this.sucess("/web/welcome");
//    }
//
//    public Map<String, Object> indexData(String time) {
//
//        Map<String, Object> map = new HashMap<>();
//
//
//        //今日钻石充值金额
//        Double todayChongzhi = 0d;
//
//        //钻石充值总金额
//        Double chongzhi = 0d;
//
//        //今日会员充值金额
//        Double todayVip = 0d;
//
//        //今日门票金额
//        Double todayMengPiao = 0d;
//
//        //会员充值总金额
//        Double todayVipAll = 0d;
//
//        //今日门票总金额
//        Double todayMengPiaoAll = 0d;
//
//        //日活跃人数
//        Integer activeNum = 0;
//
//        //今日注册会员数
//        Integer todayRegisterUsers = 0;
//
//        //会员总注册数
//        Integer users = 0;
//
//        //会员+钻石充值总金额
//        Double vipandchongzhi = 0d;
//
//        //当前钻石总余额
//        Double diamondsAll = 0d;
//
//        //当前金币总余额
//        Double jinbi = 0d;
//
//        //今日礼物订单总数
//        Integer gift = 0;
//
//        //礼物订单总金额
//        Double giftAmount = 0d;
//
//        //今日礼物订单总金额
//        Double todayGiftAmount = 0d;
//
//        //今日签到用户数
//        Integer signCountToday = 0;
//
//        //当前动态总数
//        Integer dongtai = 0;
//
//        //当前评论总数
//        Integer pinglun = 0;
//
//        //当前反馈总数
//        Integer fankui = 0;
//
//        //当前举报总数
//        Integer jubao = 0;
//
//
//        //Map
//        Map<String, Object> params;
//
//        Map<String, Object> allparams;
//
//
//        params = new HashMap<>();
//
//        if (ObjectUtil.isNotEmpty(time)) {
//
//            params.put("today", time);
//        } else {
//            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
//            String format = formatter.format(new Date());
//            params.put("today", format);
//        }
//
//        allparams = new HashMap<>();
//
//        if (ObjectUtil.isNotEmpty(time)) {
//            String hms = " 23:59:59";
//            String allTime = time + hms;
//            allparams.put("alltoday", allTime);
//        } else {
//            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//            String format = formatter.format(new Date());
//            allparams.put("alltoday", format);
//        }
//
//        //vip订单表
//        List<VipOrder> vipOrders = afterVipOrderService.list();
//        List<VipOrder> vipOrderAll = new ArrayList<>();
//        //取出所有设备号不为空的参数
//        for (int i = 0; i < vipOrders.size(); i++) {
//            VipOrder vipOrder = vipOrders.get(i);
//            if (ObjectUtil.isNotEmpty(vipOrder.getMobileSpec())) {
//                vipOrderAll.add(vipOrder);
//            }
//        }
//        //总数
//        int allPaySize = vipOrderAll.size();
//        int iPhone = 0;
//        //统计苹果
//        for (int i = 0; i < vipOrderAll.size(); i++) {
//            VipOrder vipOrder = vipOrderAll.get(i);
//            if (vipOrder.getMobileSpec().equals("iPhone")) {
//                iPhone++;
//            }
//        }
//        //安卓
//        int android = allPaySize - iPhone;
//
//        String proportion = "安卓：" + android + " 苹果：" + iPhone;
//
//
//        //今日钻石充值金额
//        todayChongzhi = appMingxiChongzhiService.total(params);
//
//
//        //钻石充值总金额
//        chongzhi = appMingxiChongzhiService.total(allparams);
//
//
//        //今日会员充值金额
//        todayVip = afterVipOrderService.total(params);
//
//
//        todayMengPiao = afterVipOrderService.todayMengPiao(params);
//
//
//        //会员充值总金额
//        todayVipAll = afterVipOrderService.total(allparams);
//
//
//        todayMengPiaoAll = afterVipOrderService.todayMengPiao(allparams);
//
//
//        //日活跃人数
//        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
//        String format = formatter.format(new Date());
//        if (ObjectUtil.isEmpty(time) || time.equals(format)) {
//            Set<String> keys = redisUtil.keys(RedisKeys.active + "*");
//            activeNum = keys.size();
//        } else {
//            activeNum = afterAppActiveService.countAppActive(params);
//        }
//
//
//        //今日注册会员数
//        List<AppUser> appUsers1 = appUserService.userCount(params);
//        todayRegisterUsers = appUsers1.size();
//
//
//        //会员总注册数
//        List<AppUser> appUsers = appUserService.userCount(new HashMap<>());
//        users = appUsers.size();
//
//
//        //会员+钻石充值总金额
//        vipandchongzhi = todayVipAll + chongzhi;
//
//
//        //当前钻石总余额
//        diamondsAll = appUsers.stream().mapToDouble(e -> Double.valueOf(e.getDiamonds().stripTrailingZeros().toPlainString())).sum();
//        diamondsAll = formatDouble(diamondsAll);
//
//
//        //当前金币总余额
//        jinbi = appUsers.stream().mapToDouble(e -> Double.valueOf(e.getJinbi().stripTrailingZeros().toPlainString())).sum();
//        jinbi = formatDouble(jinbi);
//
//        //今日礼物订单总数
//        params = new HashMap<>();
//        params.put("today", "1");
//        List<AppGiftReward> todayGift = appGiftRewardService.list(params);
//        gift = todayGift.size();
//
//        //礼物订单总金额
//        List<AppGiftReward> list = appGiftRewardService.list(new HashMap<>());
//        giftAmount = list.stream().mapToDouble(e -> e.getMoney()).sum();
//        giftAmount = formatDouble(giftAmount);
//
//
//        //今日礼物订单总金额
//        todayGiftAmount = todayGift.stream().mapToDouble(e -> e.getMoney()).sum();
//        todayGiftAmount = formatDouble(todayGiftAmount);
//
//
//        //今日签到用户数
//        params = new HashMap<>();
//        params.put("today", "1");
//        List<AppQianDaoRecord> list3 = appQianDaoRecordService.list(params);
//        signCountToday = list3.size();
//
//
//        //当前动态总数
//        List<AppDynamic> list8 = appDynamicService.list(new HashMap<>());
//        dongtai = list8.size();
//
//
//        //当前评论总数
//        pinglun = list8.stream().mapToInt(e -> e.getCommentnum()).sum();
//
//
//        //当前反馈总数
//        List<AppSuggest> list9 = appSuggestService.list(new HashMap<>());
//        fankui = list9.size();
//
//
//        //当前举报总数
//        List<AppFeedback> list10 = appFeedbackService.findList(new HashMap<>());
//        jubao = list10.size();
//
//        map.put("proportion", proportion);//充值比例
//
//        map.put("todayChongzhi", todayChongzhi);//今日钻石充值金额
//
//        map.put("chongzhi", chongzhi);//钻石充值总金额
//
//        map.put("todayVip", todayVip);//今日会员充值金额
//        map.put("todayMengPiao", todayMengPiao);//今日会员充值金额
//
//        map.put("todayVipAll", todayVipAll);//会员充值总金额
//        map.put("todayMengPiaoAll", todayMengPiaoAll);//会员充值总金额
//
//        map.put("activeToday", activeNum);//日活跃人数
//
//        map.put("todayRegisterUsers", todayRegisterUsers);//今日注册会员数
//
//        map.put("users", users);//会员总注册数
//
//        map.put("vipandchongzhi", vipandchongzhi);//会员+钻石充值总金额
//
//        map.put("diamondsAll", diamondsAll);//当前钻石总余额
//
//        map.put("jinbi", jinbi);//当前金币总余额
//
//        map.put("gift", gift);  // 今日礼物订单总数
//
//        map.put("giftAmount", giftAmount);//礼物订单总金额
//
//        map.put("todayGiftAmount", todayGiftAmount);//今日礼物订单总金额
//
//        map.put("signCountToday", signCountToday);//今日签到用户数
//
//        map.put("dongtai", dongtai);//当前动态总数
//
//        map.put("pinglun", pinglun);//当前评论总数
//
//        map.put("fankui", fankui);//当前反馈总数
//
//        map.put("jubao", jubao);//当前举报总数
//        request.setAttribute("time", time);
//        return map;
//    }


    /**
     * 欢迎界面
     *
     * @return
     */
    @RequestMapping("/welcome.html")
    public String welcome(String time) {

        User user = (User) request.getSession(false).getAttribute(Constants.access_token);

        if (ObjectUtil.isNotEmpty(user.getCode())) {
            //标题
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy年MM月dd日");
            Date date = new Date();//得到当前系统时间
            String str_date = formatter.format(date); //将日期时间格式化
            String dayNames[] = {"#星期日", "#星期一", "#星期二", "#星期三", "#星期四", "#星期五", "#星期六"};
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
            int hours = calendar.get(Calendar.HOUR_OF_DAY);

            String str_hours = (hours > 12) ? "下午好" : "上午好";
            if (hours < 6)
                str_hours = "凌晨好";
            else if (hours >= 6 && hours < 9)
                str_hours = "早上好";
            else if (hours >= 9 && hours < 12)
                str_hours = "上午好";
            else if (hours >= 12 && hours < 13)
                str_hours = "中午好";
            else if (hours >= 13 && hours < 18)
                str_hours = "下午好";
            else if (hours >= 18 && hours < 20)
                str_hours = "晚上好";
            else if (hours >= 21)
                str_hours = "夜已深,请保重身体";

            String str_week = dayNames[dayOfWeek - 1];

            Map<String, Object> stringObjectMap = indexDataGongHui(time, user);

            request.setAttribute("str_date", str_date);
            request.setAttribute("str_hours", str_hours);
            request.setAttribute("str_week", str_week);
            request.setAttribute("user", user);
            request.setAttribute("obj", stringObjectMap);
            return this.sucess("/web/welcomegonghui");
        } else {


            //5是管理员
            if (user.getId().equals(5)) {
                //标题
                SimpleDateFormat formatter = new SimpleDateFormat("yyyy年MM月dd日");
                Date date = new Date();//得到当前系统时间
                String str_date = formatter.format(date); //将日期时间格式化
                String dayNames[] = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(date);
                int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
                int hours = calendar.get(Calendar.HOUR_OF_DAY);

                String str_hours = (hours > 12) ? "下午好" : "上午好";
                if (hours < 6)
                    str_hours = "凌晨好";
                else if (hours >= 6 && hours < 9)
                    str_hours = "早上好";
                else if (hours >= 9 && hours < 12)
                    str_hours = "上午好";
                else if (hours >= 12 && hours < 13)
                    str_hours = "中午好";
                else if (hours >= 13 && hours < 18)
                    str_hours = "下午好";
                else if (hours >= 18 && hours < 20)
                    str_hours = "晚上好";
                else if (hours >= 21)
                    str_hours = "夜已深,请保重身体";

                String str_week = dayNames[dayOfWeek - 1];

                //数据
//                Map<String, Object> stringObjectMap = indexData(time);
                Map<String, Object> stringObjectMap = indexDataV2(time);

                request.setAttribute("str_date", str_date);
                request.setAttribute("str_hours", str_hours);
                request.setAttribute("str_week", str_week);
                request.setAttribute("user", user);
                request.setAttribute("obj", stringObjectMap);
                return this.sucess("/web/welcomev2");
            } else {

                //客服 抽佣
                //标题
                SimpleDateFormat formatter = new SimpleDateFormat("yyyy年MM月dd日");
                Date date = new Date();//得到当前系统时间
                String str_date = formatter.format(date); //将日期时间格式化
                String dayNames[] = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(date);
                int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
                int hours = calendar.get(Calendar.HOUR_OF_DAY);

                String str_hours = (hours > 12) ? "下午好" : "上午好";
                if (hours < 6)
                    str_hours = "凌晨好";
                else if (hours >= 6 && hours < 9)
                    str_hours = "早上好";
                else if (hours >= 9 && hours < 12)
                    str_hours = "上午好";
                else if (hours >= 12 && hours < 13)
                    str_hours = "中午好";
                else if (hours >= 13 && hours < 18)
                    str_hours = "下午好";
                else if (hours >= 18 && hours < 20)
                    str_hours = "晚上好";
                else if (hours >= 21)
                    str_hours = "夜已深,请保重身体";

                String str_week = dayNames[dayOfWeek - 1];

                Map<String, Object> stringObjectMap = indexDataKefuV2(time, user.getName());
                request.setAttribute("str_date", str_date);
                request.setAttribute("str_hours", str_hours);
                request.setAttribute("str_week", str_week);
                request.setAttribute("user", user);
                request.setAttribute("obj", stringObjectMap);

                return this.sucess("/web/welcomekefu");
            }


        }


    }

    @RequestMapping("/indexDataKefus")
    public void indexDataKefus(String time, String userName) {
        indexDataKefuV2(time, userName);
    }


    /**
     * 客服抽佣
     */

    public Map<String, Object> indexDataKefuV2(String time, String userName) {

        Map<String, Object> map = new HashMap<>();
        //获取佣金方案
        String kefuTake = appSetupDao.get().getKefuTake();

        if (ObjectUtil.isNotEmpty(kefuTake)) {
            List<KeFuDto> keFuDtos = JSON.parseArray(kefuTake, KeFuDto.class);
            //取出对应的账号
            keFuDtos.forEach(e -> {
                boolean flag = e.getAccount().equals(userName);
                if (flag) {

                    //客服名称
                    String account = e.getAccount();
                    //抽成
                    List<Integer> cc = e.getCc();

                    //时间
                    List<String> workTime = e.getTime();

                    //今日
                    Map<String, Object> todayParam;
                    todayParam = new HashMap<>();

                    //今日区间
                    Map<String, Object> todayIntervalParam1;
                    todayIntervalParam1 = new HashMap<>();


                    //今日
                    if (ObjectUtil.isNotEmpty(time)) {

                        todayParam.put("today", time);
                    } else {
                        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
                        String format = formatter.format(new Date());
                        todayParam.put("today", format);
                    }
                    //工作时间
                    if (workTime.size() == 1) {

                        String timeparam = workTime.get(0);

                        String[] split = timeparam.split("-");
                        String sTime = split[split.length - 2];
                        String eTime = split[split.length - 1];

                        //今日
                        if (ObjectUtil.isNotEmpty(time)) {

                            todayIntervalParam1.put("todayStartTime", time + " " + sTime);
                            todayIntervalParam1.put("todayEndTime", time + " " + eTime);

                        } else {
                            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
                            String format = formatter.format(new Date());
                            todayIntervalParam1.put("todayStartTime", format + " " + sTime);
                            todayIntervalParam1.put("todayEndTime", format + " " + eTime);
                        }
                        //上班时间
                        map.put("workTime", timeparam);


                        //今日vip订单
                        List<VipOrder> todayVipOrders = afterVipOrderService.getVipOrderV2(todayIntervalParam1);

                        //安卓
                        //88
                        Stream<VipOrder> today88AndroidZY = todayVipOrders.stream().filter(e1 -> !e1.getMobileSpec().equals("iPhone")).filter(e1 -> e1.getVipPackageId().equals(1));
                        //128
                        Stream<VipOrder> today128AndroidZY = todayVipOrders.stream().filter(e1 -> !e1.getMobileSpec().equals("iPhone")).filter(e1 -> e1.getVipPackageId().equals(2));
                        Stream<VipOrder> today128Android = todayVipOrders.stream().filter(e1 -> !e1.getMobileSpec().equals("iPhone")).filter(e1 -> e1.getVipPackageId().equals(101));
                        //168
                        Stream<VipOrder> today168AndroidZY = todayVipOrders.stream().filter(e1 -> !e1.getMobileSpec().equals("iPhone")).filter(e1 -> e1.getVipPackageId().equals(3));
                        Stream<VipOrder> today168Android = todayVipOrders.stream().filter(e1 -> !e1.getMobileSpec().equals("iPhone")).filter(e1 -> e1.getVipPackageId().equals(102));
                        //198
                        Stream<VipOrder> today198AndroidZY = todayVipOrders.stream().filter(e1 -> !e1.getMobileSpec().equals("iPhone")).filter(e1 -> e1.getVipPackageId().equals(7));
                        Stream<VipOrder> today198Android = todayVipOrders.stream().filter(e1 -> !e1.getMobileSpec().equals("iPhone")).filter(e1 -> e1.getVipPackageId().equals(103));

                        //
                        Integer today88AndroidNum = 0;
                        today88AndroidNum = (int) today88AndroidZY.count();
                        map.put("today88AndroidNum", today88AndroidNum);

                        Integer today128AndroidNum = 0;
                        Integer today128AndroidNumZY = 0;
                        today128AndroidNum = (int) today128AndroidZY.count();
                        today128AndroidNumZY = (int) today128Android.count();
                        map.put("today128AndroidNum", today128AndroidNum + today128AndroidNumZY);

                        Integer today168AndroidNum = 0;
                        Integer today168AndroidNumZY = 0;
                        today168AndroidNum = (int) today168AndroidZY.count();
                        today168AndroidNumZY = (int) today168Android.count();
                        map.put("today168AndroidNum", today168AndroidNum + today168AndroidNumZY);

                        Integer today198AndroidNum = 0;
                        Integer today198AndroidNumZY = 0;
                        today198AndroidNum = (int) today198AndroidZY.count();
                        today198AndroidNumZY = (int) today198Android.count();
                        map.put("today198AndroidNum", today198AndroidNum + today198AndroidNumZY);


                        //ios
                        //88
                        Stream<VipOrder> today88AppleZY = todayVipOrders.stream().filter(e2 -> e2.getMobileSpec().equals("iPhone")).filter(e2 -> e2.getVipPackageId().equals(1));
                        //128
                        Stream<VipOrder> today128AppleZY = todayVipOrders.stream().filter(e2 -> e2.getMobileSpec().equals("iPhone")).filter(e2 -> e2.getVipPackageId().equals(2));
                        Stream<VipOrder> today128Apple = todayVipOrders.stream().filter(e2 -> e2.getMobileSpec().equals("iPhone")).filter(e2 -> e2.getVipPackageId().equals(101));
                        //168
                        Stream<VipOrder> today168AppleZY = todayVipOrders.stream().filter(e2 -> e2.getMobileSpec().equals("iPhone")).filter(e2 -> e2.getVipPackageId().equals(3));
                        Stream<VipOrder> today168Apple = todayVipOrders.stream().filter(e2 -> e2.getMobileSpec().equals("iPhone")).filter(e2 -> e2.getVipPackageId().equals(102));
                        //198
                        Stream<VipOrder> today198AppleZY = todayVipOrders.stream().filter(e2 -> e2.getMobileSpec().equals("iPhone")).filter(e2 -> e2.getVipPackageId().equals(7));
                        Stream<VipOrder> today198Apple = todayVipOrders.stream().filter(e2 -> e2.getMobileSpec().equals("iPhone")).filter(e2 -> e2.getVipPackageId().equals(103));


                        //
                        Integer today88AppleNum = 0;
                        today88AppleNum = (int) today88AppleZY.count();
                        map.put("today88AppleNum", today88AppleNum);

                        Integer today128AppleNumZY = 0;
                        Integer today128AppleNum = 0;
                        today128AppleNumZY = (int) today128AppleZY.count();
                        today128AppleNum = (int) today128Apple.count();
                        map.put("today128AppleNum", today128AppleNum + today128AppleNumZY);

                        Integer today168AppleNumZY = 0;
                        Integer today168AppleNum = 0;
                        today168AppleNumZY = (int) today168AppleZY.count();
                        today168AppleNum = (int) today168Apple.count();
                        map.put("today168AppleNum", today168AppleNum + today168AppleNumZY);


                        Integer today198AppleNumZY = 0;
                        Integer today198AppleNum = 0;
                        today198AppleNumZY = (int) today198AppleZY.count();
                        today198AppleNum = (int) today198Apple.count();
                        map.put("today198AppleNum", today198AppleNum + today198AppleNumZY);


                        //今日门票
                        Integer todayTicketNum = 0;
                        Integer todayAndroidTicket = 0;
                        Integer todayAppleTicket = 0;


                        //今日门票
                        List<VipOrder> todayTickets = afterVipOrderService.getVipOrderTicketV2(todayIntervalParam1);
                        //今日门票总数量
                        todayTicketNum = todayTickets.size();
                        //今日android门票数量
                        todayAndroidTicket = Math.toIntExact(todayTickets.stream().filter(e3 -> !e3.getMobileSpec().equals("iPhone")).count());
                        //今日苹果门票数量
                        todayAppleTicket = todayTicketNum - todayAndroidTicket;


                        List<AppUser> regTodayAppUsers = appUserService.userCount(todayIntervalParam1);


                        Integer todayRegAndroid = 0;
                        Integer todayRegIphone = 0;

                        todayRegAndroid = (int) regTodayAppUsers.stream().filter(e3 -> ObjectUtil.isNotEmpty(e3.getMobileSpec())).count();
                        todayRegIphone = (int) regTodayAppUsers.stream().filter(e3 -> ObjectUtil.isEmpty(e3.getMobileSpec())).count();

                        //今日安卓注册
                        map.put("todayRegAndroid", todayRegAndroid);
                        //今日苹果注册
                        map.put("todayRegIphone", todayRegIphone);

                        String todayRegAndroidPercentage = "0.00%";
                        String todayRegIphonePercentage = "0.00%";

                        todayRegAndroidPercentage = String.format("%.2f%%", (double) todayAndroidTicket / todayRegAndroid * 100);
                        todayRegIphonePercentage = String.format("%.2f%%", (double) todayAppleTicket / todayRegIphone * 100);

                        if (todayRegAndroidPercentage.equals("NaN%")) {
                            todayRegAndroidPercentage = "0.00%";
                        }
                        if (todayRegIphonePercentage.equals("NaN%")) {
                            todayRegIphonePercentage = "0.00%";
                        }


                        //今日安卓支付注册比例
                        map.put("todayRegAndroidPercentage", todayRegAndroidPercentage);
                        //今日苹果支付注册比例
                        map.put("todayRegIphonePercentage", todayRegIphonePercentage);


                        //结算
                        Integer vip88 = 0;
                        Integer vip128 = 0;
                        Integer vip168 = 0;
                        Integer vip198 = 0;
                        Integer vipSum = 0;


                        //88
                        Stream<VipOrder> vip88Android = todayVipOrders.stream().filter(e2 -> e2.getVipPackageId().equals(1));
                        int count88 = (int) vip88Android.count();

                        vip88 = cc.get(0) * count88;


                        //128
                        Stream<VipOrder> vip128AndroidZY = todayVipOrders.stream().filter(e2 -> e2.getVipPackageId().equals(2));
                        Stream<VipOrder> vip128Android = todayVipOrders.stream().filter(e2 -> e2.getVipPackageId().equals(101));
                        int countZY128 = (int) vip128AndroidZY.count();
                        int count128 = (int) vip128Android.count();
                        int sum128 = countZY128 + count128;
                        vip128 = cc.get(1) * sum128;

                        //168
                        Stream<VipOrder> vip168AndroidZY = todayVipOrders.stream().filter(e2 -> e2.getVipPackageId().equals(3));
                        Stream<VipOrder> vip168Android = todayVipOrders.stream().filter(e2 -> e2.getVipPackageId().equals(102));
                        int countZY168 = (int) vip168AndroidZY.count();
                        int count168 = (int) vip168Android.count();

                        int sum168 = countZY168 + count168;
                        vip168 = cc.get(2) * sum168;

                        //198
                        Stream<VipOrder> vip198AndroidZY = todayVipOrders.stream().filter(e2 -> e2.getVipPackageId().equals(7));
                        Stream<VipOrder> vip198Android = todayVipOrders.stream().filter(e2 -> e2.getVipPackageId().equals(103));

                        int countZY198 = (int) vip198AndroidZY.count();
                        int count198 = (int) vip198Android.count();
                        int sum198 = countZY198 + count198;
                        vip198 = cc.get(3) * sum198;

                        map.put("vip88", vip88);
                        map.put("vip128", vip128);
                        map.put("vip168", vip168);
                        map.put("vip198", vip198);

                        vipSum = vip88 + vip128 + vip168 + vip198;
                        map.put("vipSum", vipSum);


                        //月
                        //今日vip订单


                    }
                    if (workTime.size() > 1) {

                        String timeOneParam = workTime.get(0);
                        String[] split1 = timeOneParam.split("-");
                        String sTime1 = split1[split1.length - 2];
                        String eTime1 = split1[split1.length - 1];

                        String timeTwoParam = workTime.get(1);
                        String[] split2 = timeTwoParam.split("-");
                        String sTime2 = split2[split2.length - 2];
                        String eTime2 = split2[split2.length - 1];

                        //今日
                        if (ObjectUtil.isNotEmpty(time)) {


                            todayIntervalParam1.put("todayStartTime", time + " " + sTime1);
                            todayIntervalParam1.put("todayEndTime", time + " " + eTime1);
                            todayIntervalParam1.put("todayStartTime1", time + " " + sTime2);
                            todayIntervalParam1.put("todayEndTime1", time + " " + eTime2);
                        } else {

                            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
                            String format = formatter.format(new Date());
                            todayIntervalParam1.put("todayStartTime", format + " " + sTime1);
                            todayIntervalParam1.put("todayEndTime", format + " " + eTime1);
                            todayIntervalParam1.put("todayStartTime1", format + " " + sTime2);
                            todayIntervalParam1.put("todayEndTime1", format + " " + eTime2);
                        }

                        //上班时间
                        map.put("workTime", timeOneParam + " " + timeTwoParam);

                        //今日vip订单
                        List<VipOrder> todayVipOrders = afterVipOrderService.getVipOrderV2(todayIntervalParam1);


                        //安卓
                        //88
                        Stream<VipOrder> today88AndroidZY = todayVipOrders.stream().filter(e1 -> !e1.getMobileSpec().equals("iPhone")).filter(e1 -> e1.getVipPackageId().equals(1));


                        //128
                        Stream<VipOrder> today128AndroidZY = todayVipOrders.stream().filter(e1 -> !e1.getMobileSpec().equals("iPhone")).filter(e1 -> e1.getVipPackageId().equals(2));
                        Stream<VipOrder> today128Android = todayVipOrders.stream().filter(e1 -> !e1.getMobileSpec().equals("iPhone")).filter(e1 -> e1.getVipPackageId().equals(101));
                        //168
                        Stream<VipOrder> today168AndroidZY = todayVipOrders.stream().filter(e1 -> !e1.getMobileSpec().equals("iPhone")).filter(e1 -> e1.getVipPackageId().equals(3));
                        Stream<VipOrder> today168Android = todayVipOrders.stream().filter(e1 -> !e1.getMobileSpec().equals("iPhone")).filter(e1 -> e1.getVipPackageId().equals(102));
                        //198
                        Stream<VipOrder> today198AndroidZY = todayVipOrders.stream().filter(e1 -> !e1.getMobileSpec().equals("iPhone")).filter(e1 -> e1.getVipPackageId().equals(7));
                        Stream<VipOrder> today198Android = todayVipOrders.stream().filter(e1 -> !e1.getMobileSpec().equals("iPhone")).filter(e1 -> e1.getVipPackageId().equals(103));

                        //
                        Integer today88AndroidNum = 0;
                        today88AndroidNum = (int) today88AndroidZY.count();
                        map.put("today88AndroidNum", today88AndroidNum);

                        Integer today128AndroidNum = 0;
                        Integer today128AndroidNumZY = 0;
                        today128AndroidNum = (int) today128AndroidZY.count();
                        today128AndroidNumZY = (int) today128Android.count();
                        map.put("today128AndroidNum", today128AndroidNum + today128AndroidNumZY);

                        Integer today168AndroidNum = 0;
                        Integer today168AndroidNumZY = 0;
                        today168AndroidNum = (int) today168AndroidZY.count();
                        today168AndroidNumZY = (int) today168Android.count();
                        map.put("today168AndroidNum", today168AndroidNum + today168AndroidNumZY);

                        Integer today198AndroidNum = 0;
                        Integer today198AndroidNumZY = 0;
                        today198AndroidNum = (int) today198AndroidZY.count();
                        today198AndroidNumZY = (int) today198Android.count();
                        map.put("today198AndroidNum", today198AndroidNum + today198AndroidNumZY);


                        //ios
                        //88
                        Stream<VipOrder> today88AppleZY = todayVipOrders.stream().filter(e2 -> e2.getMobileSpec().equals("iPhone")).filter(e2 -> e2.getVipPackageId().equals(1));
                        //128
                        Stream<VipOrder> today128AppleZY = todayVipOrders.stream().filter(e2 -> e2.getMobileSpec().equals("iPhone")).filter(e2 -> e2.getVipPackageId().equals(2));
                        Stream<VipOrder> today128Apple = todayVipOrders.stream().filter(e2 -> e2.getMobileSpec().equals("iPhone")).filter(e2 -> e2.getVipPackageId().equals(101));
                        //168
                        Stream<VipOrder> today168AppleZY = todayVipOrders.stream().filter(e2 -> e2.getMobileSpec().equals("iPhone")).filter(e2 -> e2.getVipPackageId().equals(3));
                        Stream<VipOrder> today168Apple = todayVipOrders.stream().filter(e2 -> e2.getMobileSpec().equals("iPhone")).filter(e2 -> e2.getVipPackageId().equals(102));
                        //198
                        Stream<VipOrder> today198AppleZY = todayVipOrders.stream().filter(e2 -> e2.getMobileSpec().equals("iPhone")).filter(e2 -> e2.getVipPackageId().equals(7));
                        Stream<VipOrder> today198Apple = todayVipOrders.stream().filter(e2 -> e2.getMobileSpec().equals("iPhone")).filter(e2 -> e2.getVipPackageId().equals(103));


                        //
                        Integer today88AppleNum = 0;
                        today88AppleNum = (int) today88AppleZY.count();
                        map.put("today88AppleNum", today88AppleNum);

                        Integer today128AppleNumZY = 0;
                        Integer today128AppleNum = 0;
                        today128AppleNumZY = (int) today128AppleZY.count();
                        today128AppleNum = (int) today128Apple.count();
                        map.put("today128AppleNum", today128AppleNum + today128AppleNumZY);

                        Integer today168AppleNumZY = 0;
                        Integer today168AppleNum = 0;
                        today168AppleNumZY = (int) today168AppleZY.count();
                        today168AppleNum = (int) today168Apple.count();
                        map.put("today168AppleNum", today168AppleNum + today168AppleNumZY);


                        Integer today198AppleNumZY = 0;
                        Integer today198AppleNum = 0;
                        today198AppleNumZY = (int) today198AppleZY.count();
                        today198AppleNum = (int) today198Apple.count();
                        map.put("today198AppleNum", today198AppleNum + today198AppleNumZY);

                        //今日门票
                        Integer todayTicketNum = 0;
                        Integer todayAndroidTicket = 0;
                        Integer todayAppleTicket = 0;


                        //今日门票
                        List<VipOrder> todayTickets = afterVipOrderService.getVipOrderTicketV2(todayIntervalParam1);
                        //今日门票总数量
                        todayTicketNum = todayTickets.size();
                        //今日android门票数量
                        todayAndroidTicket = Math.toIntExact(todayTickets.stream().filter(e3 -> !e3.getMobileSpec().equals("iPhone")).count());
                        //今日苹果门票数量
                        todayAppleTicket = todayTicketNum - todayAndroidTicket;


                        List<AppUser> regTodayAppUsers = appUserService.userCount(todayIntervalParam1);


                        Integer todayRegAndroid = 0;
                        Integer todayRegIphone = 0;

                        todayRegAndroid = (int) regTodayAppUsers.stream().filter(e3 -> ObjectUtil.isNotEmpty(e3.getMobileSpec())).count();
                        todayRegIphone = (int) regTodayAppUsers.stream().filter(e3 -> ObjectUtil.isEmpty(e3.getMobileSpec())).count();

                        //今日安卓注册
                        map.put("todayRegAndroid", todayRegAndroid);
                        //今日苹果注册
                        map.put("todayRegIphone", todayRegIphone);

                        String todayRegAndroidPercentage = "0.00%";
                        String todayRegIphonePercentage = "0.00%";

                        todayRegAndroidPercentage = String.format("%.2f%%", (double) todayAndroidTicket / todayRegAndroid * 100);
                        todayRegIphonePercentage = String.format("%.2f%%", (double) todayAppleTicket / todayRegIphone * 100);

                        if (todayRegAndroidPercentage.equals("NaN%")) {
                            todayRegAndroidPercentage = "0.00%";
                        }
                        if (todayRegIphonePercentage.equals("NaN%")) {
                            todayRegIphonePercentage = "0.00%";
                        }


                        //今日安卓支付注册比例
                        map.put("todayRegAndroidPercentage", todayRegAndroidPercentage);
                        //今日苹果支付注册比例
                        map.put("todayRegIphonePercentage", todayRegIphonePercentage);


                        //结算
                        Integer vip88 = 0;
                        Integer vip128 = 0;
                        Integer vip168 = 0;
                        Integer vip198 = 0;
                        Integer vipSum = 0;


                        //88
                        Stream<VipOrder> vip88Android = todayVipOrders.stream().filter(e2 -> e2.getVipPackageId().equals(1));
                        int count88 = (int) vip88Android.count();

                        vip88 = cc.get(0) * count88;


                        //128
                        Stream<VipOrder> vip128AndroidZY = todayVipOrders.stream().filter(e2 -> e2.getVipPackageId().equals(2));
                        Stream<VipOrder> vip128Android = todayVipOrders.stream().filter(e2 -> e2.getVipPackageId().equals(101));
                        int countZY128 = (int) vip128AndroidZY.count();
                        int count128 = (int) vip128Android.count();
                        int sum128 = countZY128 + count128;
                        vip128 = cc.get(1) * sum128;

                        //168
                        Stream<VipOrder> vip168AndroidZY = todayVipOrders.stream().filter(e2 -> e2.getVipPackageId().equals(3));
                        Stream<VipOrder> vip168Android = todayVipOrders.stream().filter(e2 -> e2.getVipPackageId().equals(102));
                        int countZY168 = (int) vip168AndroidZY.count();
                        int count168 = (int) vip168Android.count();

                        int sum168 = countZY168 + count168;
                        vip168 = cc.get(2) * sum168;

                        //198
                        Stream<VipOrder> vip198AndroidZY = todayVipOrders.stream().filter(e2 -> e2.getVipPackageId().equals(7));
                        Stream<VipOrder> vip198Android = todayVipOrders.stream().filter(e2 -> e2.getVipPackageId().equals(103));

                        int countZY198 = (int) vip198AndroidZY.count();
                        int count198 = (int) vip198Android.count();
                        int sum198 = countZY198 + count198;
                        vip198 = cc.get(3) * sum198;

                        map.put("vip88", vip88);
                        map.put("vip128", vip128);
                        map.put("vip168", vip168);
                        map.put("vip198", vip198);

                        vipSum = vip88 + vip128 + vip168 + vip198;
                        map.put("vipSum", vipSum);


                    }


                    //基础数据
                    Integer activeNum = 0;
                    //日活跃人数
                    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
                    String format = formatter.format(new Date());
                    if (ObjectUtil.isEmpty(time) || time.equals(format)) {
                        Set<String> keys = redisUtil.keys(RedisKeys.active + "*");
                        activeNum = keys.size();
                    } else {
                        activeNum = afterAppActiveService.countAppActive(todayParam);
                    }
                    map.put("activeNum", activeNum);


                    Integer todayRegisterUsers = 0;
                    //今日注册会员数
                    List<AppUser> appUsers1 = appUserService.userCount(todayParam);
                    todayRegisterUsers = appUsers1.size();
                    map.put("todayRegisterUsers", todayRegisterUsers);


                    Integer users = 0;
                    //会员总注册数
                    List<AppUser> appUsers = appUserService.userCount(new HashMap<>());
                    users = appUsers.size();

                    map.put("users", users);

                    request.setAttribute("time", time);

                }
            });


            return map;
        }




        return map;
    }

    public Map<String, Object> indexDataKefu(String time) {


        Map<String, Object> map = new HashMap<>();

        //今日
        Map<String, Object> todayParam;
        todayParam = new HashMap<>();
        //今日区间
        Map<String, Object> todayIntervalParam;
        todayIntervalParam = new HashMap<>();


        //今日
        if (ObjectUtil.isNotEmpty(time)) {

            todayParam.put("today", time);
        } else {
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
            String format = formatter.format(new Date());
            todayParam.put("today", format);
        }

        //今日
        if (ObjectUtil.isNotEmpty(time)) {

            todayIntervalParam.put("todayStartTime", time + " 8:00");
            todayIntervalParam.put("todayEndTime", time + " 20:00");
        } else {
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
            String format = formatter.format(new Date());
            todayIntervalParam.put("todayStartTime", format + " 8:00");
            todayIntervalParam.put("todayEndTime", format + " 20:00");
        }

        //今日vip订单
        List<VipOrder> todayVipOrders = afterVipOrderService.getVipOrderV2(todayIntervalParam);

        //安卓
        //88
        Stream<VipOrder> today88AndroidZY = todayVipOrders.stream().filter(e -> !e.getMobileSpec().equals("iPhone")).filter(e -> e.getVipPackageId().equals(1));
        //128
        Stream<VipOrder> today128AndroidZY = todayVipOrders.stream().filter(e -> !e.getMobileSpec().equals("iPhone")).filter(e -> e.getVipPackageId().equals(2));
        Stream<VipOrder> today128Android = todayVipOrders.stream().filter(e -> !e.getMobileSpec().equals("iPhone")).filter(e -> e.getVipPackageId().equals(101));
        //168
        Stream<VipOrder> today168AndroidZY = todayVipOrders.stream().filter(e -> !e.getMobileSpec().equals("iPhone")).filter(e -> e.getVipPackageId().equals(3));
        Stream<VipOrder> today168Android = todayVipOrders.stream().filter(e -> !e.getMobileSpec().equals("iPhone")).filter(e -> e.getVipPackageId().equals(102));
        //198
        Stream<VipOrder> today198AndroidZY = todayVipOrders.stream().filter(e -> !e.getMobileSpec().equals("iPhone")).filter(e -> e.getVipPackageId().equals(7));
        Stream<VipOrder> today198Android = todayVipOrders.stream().filter(e -> !e.getMobileSpec().equals("iPhone")).filter(e -> e.getVipPackageId().equals(103));

        //
        Integer today88AndroidNum = 0;
        today88AndroidNum = (int) today88AndroidZY.count();
        map.put("today88AndroidNum", today88AndroidNum);

        Integer today128AndroidNum = 0;
        Integer today128AndroidNumZY = 0;
        today128AndroidNum = (int) today128AndroidZY.count();
        today128AndroidNumZY = (int) today128Android.count();
        map.put("today128AndroidNum", today128AndroidNum + today128AndroidNumZY);

        Integer today168AndroidNum = 0;
        Integer today168AndroidNumZY = 0;
        today168AndroidNum = (int) today168AndroidZY.count();
        today168AndroidNumZY = (int) today168Android.count();
        map.put("today168AndroidNum", today168AndroidNum + today168AndroidNumZY);

        Integer today198AndroidNum = 0;
        Integer today198AndroidNumZY = 0;
        today198AndroidNum = (int) today198AndroidZY.count();
        today198AndroidNumZY = (int) today198Android.count();
        map.put("today198AndroidNum", today198AndroidNum + today198AndroidNumZY);


        //ios
        //88
        Stream<VipOrder> today88AppleZY = todayVipOrders.stream().filter(e -> e.getMobileSpec().equals("iPhone")).filter(e -> e.getVipPackageId().equals(1));
        //128
        Stream<VipOrder> today128AppleZY = todayVipOrders.stream().filter(e -> !e.getMobileSpec().equals("iPhone")).filter(e -> e.getVipPackageId().equals(2));
        Stream<VipOrder> today128Apple = todayVipOrders.stream().filter(e -> e.getMobileSpec().equals("iPhone")).filter(e -> e.getVipPackageId().equals(101));
        //168
        Stream<VipOrder> today168AppleZY = todayVipOrders.stream().filter(e -> e.getMobileSpec().equals("iPhone")).filter(e -> e.getVipPackageId().equals(3));
        Stream<VipOrder> today168Apple = todayVipOrders.stream().filter(e -> e.getMobileSpec().equals("iPhone")).filter(e -> e.getVipPackageId().equals(102));
        //198
        Stream<VipOrder> today198AppleZY = todayVipOrders.stream().filter(e -> e.getMobileSpec().equals("iPhone")).filter(e -> e.getVipPackageId().equals(7));
        Stream<VipOrder> today198Apple = todayVipOrders.stream().filter(e -> e.getMobileSpec().equals("iPhone")).filter(e -> e.getVipPackageId().equals(103));


        //
        Integer today88AppleNum = 0;
        today88AppleNum = (int) today88AppleZY.count();
        map.put("today88AppleNum", today88AppleNum);

        Integer today128AppleNumZY = 0;
        Integer today128AppleNum = 0;
        today128AppleNumZY = (int) today128AppleZY.count();
        today128AppleNum = (int) today128Apple.count();
        map.put("today128AppleNum", today128AppleNum + today128AppleNumZY);

        Integer today168AppleNumZY = 0;
        Integer today168AppleNum = 0;
        today168AppleNumZY = (int) today168AppleZY.count();
        today168AppleNum = (int) today168Apple.count();
        map.put("today168AppleNum", today168AppleNum + today168AppleNumZY);

        Integer today198AppleNumZY = 0;
        Integer today198AppleNum = 0;
        today198AppleNumZY = (int) today198AppleZY.count();
        today198AppleNum = (int) today198Apple.count();
        map.put("today168AppleNum", today198AppleNum + today198AppleNumZY);


        //今日门票
        Integer todayTicketNum = 0;
        Integer todayAndroidTicket = 0;
        Integer todayAppleTicket = 0;
        Double todayTicketPrice = 0d;

        //今日门票
        List<VipOrder> todayTickets = afterVipOrderService.getVipOrderTicketV2(todayIntervalParam);
        //今日门票总数量
        todayTicketNum = todayTickets.size();
        //今日门票总金额
        todayTicketPrice = todayTickets.stream().filter(Objects::nonNull).mapToDouble(e -> Double.parseDouble(e.getPrice().stripTrailingZeros().toPlainString())).sum();
        //今日android门票数量
        todayAndroidTicket = Math.toIntExact(todayTickets.stream().filter(e -> !e.getMobileSpec().equals("iPhone")).count());
        //今日苹果门票数量
        todayAppleTicket = todayTicketNum - todayAndroidTicket;


        List<AppUser> regTodayAppUsers = appUserService.userCount(todayIntervalParam);


        Integer todayRegAndroid = 0;
        Integer todayRegIphone = 0;

        todayRegAndroid = (int) regTodayAppUsers.stream().filter(e -> ObjectUtil.isNotEmpty(e.getMobileSpec())).count();
        todayRegIphone = (int) regTodayAppUsers.stream().filter(e -> ObjectUtil.isEmpty(e.getMobileSpec())).count();

        //今日安卓注册
        map.put("todayRegAndroid", todayRegAndroid);
        //今日苹果注册
        map.put("todayRegIphone", todayRegIphone);

        String todayRegAndroidPercentage = "0.00%";
        String todayRegIphonePercentage = "0.00%";

        todayRegAndroidPercentage = String.format("%.2f%%", (double) todayAndroidTicket / todayRegAndroid * 100);
        todayRegIphonePercentage = String.format("%.2f%%", (double) todayAppleTicket / todayRegIphone * 100);

        if (todayRegAndroidPercentage.equals("NaN%")) {
            todayRegAndroidPercentage = "0.00%";
        }
        if (todayRegIphonePercentage.equals("NaN%")) {
            todayRegIphonePercentage = "0.00%";
        }


        //今日安卓支付注册比例
        map.put("todayRegAndroidPercentage", todayRegAndroidPercentage);
        //今日苹果支付注册比例
        map.put("todayRegIphonePercentage", todayRegIphonePercentage);


        Integer activeNum = 0;
        //日活跃人数
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        String format = formatter.format(new Date());
        if (ObjectUtil.isEmpty(time) || time.equals(format)) {
            Set<String> keys = redisUtil.keys(RedisKeys.active + "*");
            activeNum = keys.size();
        } else {
            activeNum = afterAppActiveService.countAppActive(todayParam);
        }
        map.put("activeNum", activeNum);


        Integer todayRegisterUsers = 0;
        //今日注册会员数
        List<AppUser> appUsers1 = appUserService.userCount(todayParam);
        todayRegisterUsers = appUsers1.size();
        map.put("todayRegisterUsers", todayRegisterUsers);


        Integer users = 0;
        //会员总注册数
        List<AppUser> appUsers = appUserService.userCount(new HashMap<>());
        users = appUsers.size();

        map.put("users", users);

        request.setAttribute("time", time);
        return map;
    }


    /**
     * 新版本
     *
     * @param time
     * @return
     */
    public Map<String, Object> indexDataV2(String time) {

        Map<String, Object> map = new HashMap<>();

        //今日
        Map<String, Object> todayParam;
        todayParam = new HashMap<>();
        //本月
        Map<String, Object> monthParam;
        monthParam = new HashMap<>();
        //总
        Map<String, Object> allParam;
        allParam = new HashMap<>();


        //今日
        if (ObjectUtil.isNotEmpty(time)) {

            todayParam.put("today", time);
        } else {
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
            String format = formatter.format(new Date());
            todayParam.put("today", format);
        }
        //本月
        if (ObjectUtil.isNotEmpty(time)) {

            monthParam.put("month", time.substring(0, 7));
        } else {
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
            String format = formatter.format(new Date());
            monthParam.put("month", format.substring(0, 7));
        }
        //总的
        if (ObjectUtil.isNotEmpty(time)) {
            String hms = " 23:59:59";
            String allTime = time + hms;
            allParam.put("all", allTime);
        } else {
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String format = formatter.format(new Date());
            allParam.put("all", format);
        }


        Integer todayTicketNum = 0;
        Integer todayAndroidTicket = 0;
        Integer todayAppleTicket = 0;
        Double todayTicketPrice = 0d;

        //今日门票
        List<VipOrder> todayTickets = afterVipOrderService.getVipOrderTicketV2(todayParam);
        //今日门票总数量
        todayTicketNum = todayTickets.size();
        //今日门票总金额
        todayTicketPrice = todayTickets.stream().filter(Objects::nonNull).mapToDouble(e -> Double.parseDouble(e.getPrice().stripTrailingZeros().toPlainString())).sum();
        //今日android门票数量
        todayAndroidTicket = Math.toIntExact(todayTickets.stream().filter(e -> !e.getMobileSpec().equals("iPhone")).count());
        //今日苹果门票数量
        todayAppleTicket = todayTicketNum - todayAndroidTicket;


        //今日门票总数量
        map.put("todayTicketNum", todayTicketNum);
        //今日android门票数量
        map.put("todayAndroidTicket", todayAndroidTicket);
        //今日苹果门票数量
        map.put("todayAppleTicket", todayAppleTicket);
        //今日门票总金额
        map.put("todayTicketPrice", todayTicketPrice);


        //今日注册总人数
        Integer regTodayAppUserCount = 0;
        List<AppUser> regTodayAppUsers = appUserService.userCount(todayParam);
        regTodayAppUserCount = regTodayAppUsers.size();


        Integer todayRegAndroid = 0;
        Integer todayRegIphone = 0;

        todayRegAndroid = (int) regTodayAppUsers.stream().filter(e -> ObjectUtil.isNotEmpty(e.getMobileSpec())).count();
        todayRegIphone = (int) regTodayAppUsers.stream().filter(e -> ObjectUtil.isEmpty(e.getMobileSpec())).count();

        //今日安卓注册
        map.put("todayRegAndroid", todayRegAndroid);
        //今日苹果注册
        map.put("todayRegIphone", todayRegIphone);

        String todayRegAndroidPercentage = "0.00%";
        String todayRegIphonePercentage = "0.00%";
        String todayPercentage = "0.00%";

        todayRegAndroidPercentage = String.format("%.2f%%", (double) todayAndroidTicket / todayRegAndroid * 100);
        todayRegIphonePercentage = String.format("%.2f%%", (double) todayAppleTicket / todayRegIphone * 100);
        todayPercentage = String.format("%.2f%%", (double) todayTicketNum / regTodayAppUserCount * 100);

        //今日安卓支付注册比例
        map.put("todayRegAndroidPercentage", todayRegAndroidPercentage);
        //今日苹果支付注册比例
        map.put("todayRegIphonePercentage", todayRegIphonePercentage);
        //今日安卓苹果支付注册总比例
        map.put("todayPercentage", todayPercentage);


        Integer monthTicketNum = 0;
        Integer monthAndroidTicket = 0;
        Integer monthAppleTicket = 0;
        Double monthTicketPrice = 0d;

        //本月门票
        List<VipOrder> monthTickets = afterVipOrderService.getVipOrderTicketV2(monthParam);
        //本月门票总数量
        monthTicketNum = monthTickets.size();
        //本月门票总金额
        monthTicketPrice = monthTickets.stream().filter(Objects::nonNull).mapToDouble(e -> Double.parseDouble(e.getPrice().stripTrailingZeros().toPlainString())).sum();
        //本月android门票数量
        monthAndroidTicket = Math.toIntExact(monthTickets.stream().filter(e -> !e.getMobileSpec().equals("iPhone")).count());
        //本月苹果门票数量
        monthAppleTicket = monthTicketNum - monthAndroidTicket;

        //本月门票总数量
        map.put("monthTicketNum", monthTicketNum);
        //本月android门票数量
        map.put("monthAndroidTicket", monthAndroidTicket);
        //本月苹果门票数量
        map.put("monthAppleTicket", monthAppleTicket);
        //本月门票总金额
        map.put("monthTicketPrice", monthTicketPrice);


        //本月注册总人数
        Integer regMonthAppUserCount = 0;
        List<AppUser> regMonthAppUsers = appUserService.userCount(monthParam);
        regMonthAppUserCount = regMonthAppUsers.size();


        Integer monthRegAndroid = 0;
        Integer monthRegIphone = 0;

        monthRegAndroid = (int) regMonthAppUsers.stream().filter(e -> ObjectUtil.isNotEmpty(e.getMobileSpec())).count();
        monthRegIphone = (int) regMonthAppUsers.stream().filter(e -> ObjectUtil.isEmpty(e.getMobileSpec())).count();

        //本月安卓注册
        map.put("monthRegAndroid", monthRegAndroid);
        //本月苹果注册
        map.put("monthRegIphone", monthRegIphone);

        String monthRegAndroidPercentage = "0.00%";
        String monthRegIphonePercentage = "0.00%";
        String monthPercentage = "0.00%";

        monthRegAndroidPercentage = String.format("%.2f%%", (double) monthAndroidTicket / monthRegAndroid * 100);
        monthRegIphonePercentage = String.format("%.2f%%", (double) monthAppleTicket / monthRegIphone * 100);
        monthPercentage = String.format("%.2f%%", (double) monthTicketNum / regMonthAppUserCount * 100);

        //本月安卓支付注册比例
        map.put("monthRegAndroidPercentage", monthRegAndroidPercentage);
        //本月苹果支付注册比例
        map.put("monthRegIphonePercentage", monthRegIphonePercentage);
        //本月安卓苹果支付注册总比例
        map.put("monthPercentage", monthPercentage);


        Integer todayVipNum = 0;
        Double todayVipPrice = 0d;
        Integer todayAndroidVip = 0;
        Integer todayAppleVip = 0;
        //今日vip
        List<VipOrder> todayVips = afterVipOrderService.getVipOrderV2(todayParam);
        //今日Vip总数量
        todayVipNum = todayVips.size();
        //今日Vip总金额
        todayVipPrice = todayVips.stream().filter(Objects::nonNull).mapToDouble(e -> Double.parseDouble(e.getPrice().stripTrailingZeros().toPlainString())).sum();
        //今日androidVip数量
        todayAndroidVip = Math.toIntExact(todayVips.stream().filter(e -> !e.getMobileSpec().equals("iPhone")).count());
        //今日苹果Vip数量
        todayAppleVip = todayVipNum - todayAndroidVip;


//        map.put("todayVipNum", todayVipNum);
        map.put("todayVipPrice", todayVipPrice);
        map.put("todayAndroidVip", todayAndroidVip);
        map.put("todayAppleVip", todayAppleVip);

        //vip类型   1个月 3个月  12个月
        //安卓
        Stream<VipOrder> todayThreeDayAndroidZY = todayVips.stream().filter(e -> !e.getMobileSpec().equals("iPhone")).filter(e -> e.getVipPackageId().equals(1));
        Stream<VipOrder> todayOneAndroid = todayVips.stream().filter(e -> !e.getMobileSpec().equals("iPhone")).filter(e -> e.getVipPackageId().equals(101));
        Stream<VipOrder> todayOneAndroidZY = todayVips.stream().filter(e -> !e.getMobileSpec().equals("iPhone")).filter(e -> e.getVipPackageId().equals(2));
        Stream<VipOrder> todayThreeAndroid = todayVips.stream().filter(e -> !e.getMobileSpec().equals("iPhone")).filter(e -> e.getVipPackageId().equals(102));
        Stream<VipOrder> todayThreeAndroidZY = todayVips.stream().filter(e -> !e.getMobileSpec().equals("iPhone")).filter(e -> e.getVipPackageId().equals(3));
        Stream<VipOrder> todayTwelveAndroid = todayVips.stream().filter(e -> !e.getMobileSpec().equals("iPhone")).filter(e -> e.getVipPackageId().equals(103));
        Stream<VipOrder> todayTwelveAndroidZY = todayVips.stream().filter(e -> !e.getMobileSpec().equals("iPhone")).filter(e -> e.getVipPackageId().equals(7));

        Integer todayThreeDayAndroidNum = 0;
        todayThreeDayAndroidNum = (int) todayThreeDayAndroidZY.count();
        map.put("todayThreeDayAndroidNum", todayThreeDayAndroidNum);

        Integer todayOneAndroidNum = 0;
        Integer todayOneAndroidNumZY = 0;
        todayOneAndroidNum = (int) todayOneAndroid.count();
        todayOneAndroidNumZY = (int) todayOneAndroidZY.count();
        map.put("todayOneAndroidNum", todayOneAndroidNum + todayOneAndroidNumZY);

        Integer todayThreeAndroidNum = 0;
        Integer todayThreeAndroidNumZY = 0;
        todayThreeAndroidNum = (int) todayThreeAndroid.count();
        todayThreeAndroidNumZY = (int) todayThreeAndroidZY.count();
        map.put("todayThreeAndroidNum", todayThreeAndroidNum + todayThreeAndroidNumZY);

        Integer todayTwelveAndroidNum = 0;
        Integer todayTwelveAndroidNumZY = 0;
        todayTwelveAndroidNum = (int) todayTwelveAndroid.count();
        todayTwelveAndroidNumZY = (int) todayTwelveAndroidZY.count();
        map.put("todayTwelveAndroidNum", todayTwelveAndroidNum + todayTwelveAndroidNumZY);

        Integer todayAndroidNumSum = todayOneAndroidNum + todayThreeAndroidNum + todayTwelveAndroidNum
                + todayThreeDayAndroidNum + todayOneAndroidNumZY + todayThreeAndroidNumZY + todayTwelveAndroidNumZY;

        map.put("todayAndroidNumSum", todayAndroidNumSum);

        //ios
        Stream<VipOrder> todayThreeDayApple = todayVips.stream().filter(e -> e.getMobileSpec().equals("iPhone")).filter(e -> e.getVipPackageId().equals(1));
        Stream<VipOrder> todayOneApple = todayVips.stream().filter(e -> e.getMobileSpec().equals("iPhone")).filter(e -> e.getVipPackageId().equals(101));
        Stream<VipOrder> todayOneAppleZY = todayVips.stream().filter(e -> e.getMobileSpec().equals("iPhone")).filter(e -> e.getVipPackageId().equals(2));
        Stream<VipOrder> todayThreeApple = todayVips.stream().filter(e -> e.getMobileSpec().equals("iPhone")).filter(e -> e.getVipPackageId().equals(102));
        Stream<VipOrder> todayThreeAppleZY = todayVips.stream().filter(e -> e.getMobileSpec().equals("iPhone")).filter(e -> e.getVipPackageId().equals(3));
        Stream<VipOrder> todayTwelveApple = todayVips.stream().filter(e -> e.getMobileSpec().equals("iPhone")).filter(e -> e.getVipPackageId().equals(103));
        Stream<VipOrder> todayTwelveAppleZY = todayVips.stream().filter(e -> e.getMobileSpec().equals("iPhone")).filter(e -> e.getVipPackageId().equals(7));


        Integer todayThreeDayAppleNum = 0;
        todayThreeDayAppleNum = (int) todayThreeDayApple.count();
        map.put("todayThreeDayAppleNum", todayThreeDayAppleNum);

        Integer todayOneAppleNum = 0;
        Integer todayOneAppleNumZY = 0;
        todayOneAppleNum = (int) todayOneApple.count();
        todayOneAppleNumZY = (int) todayOneAppleZY.count();
        map.put("todayOneAppleNum", todayOneAppleNum + todayOneAppleNumZY);


        Integer todayThreeAppleNum = 0;
        Integer todayThreeAppleNumZY = 0;
        todayThreeAppleNum = (int) todayThreeApple.count();
        todayThreeAppleNumZY = (int) todayThreeAppleZY.count();
        map.put("todayThreeAppleNum", todayThreeAppleNum + todayThreeAppleNumZY);


        Integer todayTwelveAppleNum = 0;
        Integer todayTwelveAppleNumZY = 0;
        todayTwelveAppleNum = (int) todayTwelveApple.count();
        todayTwelveAppleNumZY = (int) todayTwelveAppleZY.count();
        map.put("todayTwelveAppleNum", todayTwelveAppleNum + todayTwelveAppleNumZY);

        Integer todayAppleNum = todayOneAppleNum + todayThreeAppleNum + todayTwelveAppleNum
                + todayThreeDayAppleNum + todayOneAppleNumZY + todayThreeAppleNumZY + todayTwelveAppleNumZY;
        map.put("todayAppleNum", todayAppleNum);


        Integer monthVipNum = 0;
        Double monthVipPrice = 0d;
        Integer monthAndroidVip = 0;
        Integer monthAppleVip = 0;
        //本月vip
        List<VipOrder> monthVips = afterVipOrderService.getVipOrderV2(monthParam);
        //总门票数量
        monthVipNum = monthVips.size();
        //总门票金额
        monthVipPrice = monthVips.stream().filter(Objects::nonNull).mapToDouble(e -> Double.parseDouble(e.getPrice().stripTrailingZeros().toPlainString())).sum();
        //android
        monthAndroidVip = Math.toIntExact(monthVips.stream().filter(e -> !e.getMobileSpec().equals("iPhone")).count());
        //苹果
        monthAppleVip = monthVipNum - monthAndroidVip;


        map.put("monthVipNum", monthVipNum);
        map.put("monthVipPrice", monthVipPrice);
        map.put("monthAndroidVip", monthAndroidVip);
        map.put("monthAppleVip", monthAppleVip);


        //vip类型   1个月 3个月  12个月
        //安卓
        Stream<VipOrder> monthThreeDayAndroid = monthVips.stream().filter(e -> !e.getMobileSpec().equals("iPhone")).filter(e -> e.getVipPackageId().equals(1));
        Stream<VipOrder> monthOneAndroid = monthVips.stream().filter(e -> !e.getMobileSpec().equals("iPhone")).filter(e -> e.getVipPackageId().equals(101));
        Stream<VipOrder> monthOneAndroidZY = monthVips.stream().filter(e -> !e.getMobileSpec().equals("iPhone")).filter(e -> e.getVipPackageId().equals(2));
        Stream<VipOrder> monthThreeAndroid = monthVips.stream().filter(e -> !e.getMobileSpec().equals("iPhone")).filter(e -> e.getVipPackageId().equals(102));
        Stream<VipOrder> monthThreeAndroidZY = monthVips.stream().filter(e -> !e.getMobileSpec().equals("iPhone")).filter(e -> e.getVipPackageId().equals(3));
        Stream<VipOrder> monthTwelveAndroid = monthVips.stream().filter(e -> !e.getMobileSpec().equals("iPhone")).filter(e -> e.getVipPackageId().equals(103));
        Stream<VipOrder> monthTwelveAndroidZY = monthVips.stream().filter(e -> !e.getMobileSpec().equals("iPhone")).filter(e -> e.getVipPackageId().equals(7));

        Integer monthThreeDayAndroidNum = 0;
        monthThreeDayAndroidNum = (int) monthThreeDayAndroid.count();
        map.put("monthThreeDayAndroidNum", monthThreeDayAndroidNum);

        Integer monthOneAndroidNum = 0;
        Integer monthOneAndroidNumZY = 0;
        monthOneAndroidNum = (int) monthOneAndroid.count();
        monthOneAndroidNumZY = (int) monthOneAndroidZY.count();
        map.put("monthOneAndroidNum", monthOneAndroidNum + monthOneAndroidNumZY);

        Integer monthThreeAndroidNum = 0;
        Integer monthThreeAndroidNumZY = 0;
        monthThreeAndroidNum = (int) monthThreeAndroid.count();
        monthThreeAndroidNumZY = (int) monthThreeAndroidZY.count();
        map.put("monthThreeAndroidNum", monthThreeAndroidNumZY);

        Integer monthTwelveAndroidNum = 0;
        Integer monthTwelveAndroidNumZY = 0;
        monthTwelveAndroidNum = (int) monthTwelveAndroid.count();
        monthTwelveAndroidNumZY = (int) monthTwelveAndroidZY.count();
        map.put("monthTwelveAndroidNum", monthTwelveAndroidNum + monthTwelveAndroidNumZY);

        Integer monthAndroidNumSum = monthOneAndroidNum + monthThreeAndroidNum + monthTwelveAndroidNum
                + monthThreeDayAndroidNum + monthOneAndroidNumZY + monthThreeAndroidNumZY + monthTwelveAndroidNumZY;
        map.put("monthAndroidNumSum", monthAndroidNumSum);

        //ios
        Stream<VipOrder> monthThreeDayApple = monthVips.stream().filter(e -> e.getMobileSpec().equals("iPhone")).filter(e -> e.getVipPackageId().equals(1));
        Stream<VipOrder> monthOneApple = monthVips.stream().filter(e -> e.getMobileSpec().equals("iPhone")).filter(e -> e.getVipPackageId().equals(101));
        Stream<VipOrder> monthOneAppleZY = monthVips.stream().filter(e -> e.getMobileSpec().equals("iPhone")).filter(e -> e.getVipPackageId().equals(2));
        Stream<VipOrder> monthThreeApple = monthVips.stream().filter(e -> e.getMobileSpec().equals("iPhone")).filter(e -> e.getVipPackageId().equals(102));
        Stream<VipOrder> monthThreeAppleZY = monthVips.stream().filter(e -> e.getMobileSpec().equals("iPhone")).filter(e -> e.getVipPackageId().equals(3));
        Stream<VipOrder> monthTwelveApple = monthVips.stream().filter(e -> e.getMobileSpec().equals("iPhone")).filter(e -> e.getVipPackageId().equals(103));
        Stream<VipOrder> monthTwelveAppleZY = monthVips.stream().filter(e -> e.getMobileSpec().equals("iPhone")).filter(e -> e.getVipPackageId().equals(7));


        Integer monthThreeDayAppleNum = 0;
        monthThreeDayAppleNum = (int) monthThreeDayApple.count();
        map.put("monthThreeDayAppleNum", monthThreeDayAppleNum);


        Integer monthOneAppleNum = 0;
        Integer monthOneAppleNumZY = 0;
        monthOneAppleNum = (int) monthOneApple.count();
        monthOneAppleNumZY = (int) monthOneAppleZY.count();
        map.put("monthOneAppleNum", monthOneAppleNum + monthOneAppleNumZY);


        Integer monthThreeAppleNum = 0;
        Integer monthThreeAppleNumZY = 0;
        monthThreeAppleNum = (int) monthThreeApple.count();
        monthThreeAppleNumZY = (int) monthThreeAppleZY.count();
        map.put("monthThreeAppleNum", monthThreeAppleNum + monthThreeAppleNumZY);


        Integer monthTwelveAppleNum = 0;
        Integer monthTwelveAppleNumZY = 0;
        monthTwelveAppleNum = (int) monthTwelveApple.count();
        monthTwelveAppleNumZY = (int) monthTwelveAppleZY.count();
        map.put("monthTwelveAppleNum", monthTwelveAppleNum + monthTwelveAppleNumZY);

        Integer monthAppleNum = monthOneAppleNum + monthThreeAppleNum + monthTwelveAppleNum
                + monthThreeDayAppleNum + monthOneAppleNumZY + monthThreeAppleNumZY + monthTwelveAppleNumZY;
        map.put("monthAppleNum", monthAppleNum);


        Double todayDiamondPrice = 0d;
        Double todayAndroidDiamondPrice = 0d;
        Double todayAppleDiamondPrice = 0d;

        //今日钻石
        List<AppOrder> todayAppOrders = afterOrderService.getAppOrderV2(todayParam);
        //总钻石金额
        todayDiamondPrice = todayAppOrders.stream().filter(Objects::nonNull).mapToDouble(e -> Double.parseDouble(e.getMoney().stripTrailingZeros().toPlainString())).sum();
        //android
        todayAndroidDiamondPrice = todayAppOrders.stream().filter(e -> !e.getMobileSpec().equals("iPhone")).mapToDouble(e -> Double.parseDouble(e.getMoney().stripTrailingZeros().toPlainString())).sum();
        //apple
        todayAppleDiamondPrice = todayAppOrders.stream().filter(e -> e.getMobileSpec().equals("iPhone")).mapToDouble(e -> Double.parseDouble(e.getMoney().stripTrailingZeros().toPlainString())).sum();


        map.put("todayDiamondPrice", todayDiamondPrice);
        map.put("todayAndroidDiamondPrice", todayAndroidDiamondPrice);
        map.put("todayAppleDiamondPrice", todayAppleDiamondPrice);


        Double monthDiamondPrice = 0d;
        Double monthAndroidDiamondPrice = 0d;
        Double monthAppleDiamondPrice = 0d;
        //本月钻石
        List<AppOrder> monthAppOrders = afterOrderService.getAppOrderV2(monthParam);
        //总钻石金额
        monthDiamondPrice = monthAppOrders.stream().filter(Objects::nonNull).mapToDouble(e -> Double.parseDouble(e.getMoney().stripTrailingZeros().toPlainString())).sum();
        //android
        monthAndroidDiamondPrice = monthAppOrders.stream().filter(e -> !e.getMobileSpec().equals("iPhone")).mapToDouble(e -> Double.parseDouble(e.getMoney().stripTrailingZeros().toPlainString())).sum();
        //apple
        monthAppleDiamondPrice = monthAppOrders.stream().filter(e -> e.getMobileSpec().equals("iPhone")).mapToDouble(e -> Double.parseDouble(e.getMoney().stripTrailingZeros().toPlainString())).sum();


        map.put("monthDiamondPrice", monthDiamondPrice);
        map.put("monthAndroidDiamondPrice", monthAndroidDiamondPrice);
        map.put("monthAppleDiamondPrice", monthAppleDiamondPrice);


        //今日总计：
        Double todaySum = 0d;

        //本月总计：
        Double monthSum = 0d;

        todaySum = todayTicketPrice + todayVipPrice + todayDiamondPrice;
        monthSum = monthTicketPrice + monthVipPrice + monthDiamondPrice;
        map.put("todaySum", todaySum);
        map.put("monthSum", monthSum);


        //月:门票:  VIP: 钻石:  总:
        Double sumTicketMonth = 0d;
        Double sumVipMonth = 0d;
        Double sumDiamondMonth = 0d;
        Double sumAllMonth = 0d;
        sumTicketMonth = monthTicketPrice;
        BigDecimal a1 = new BigDecimal(Double.toString(sumTicketMonth));

        sumVipMonth = monthVipPrice;
        BigDecimal a2 = new BigDecimal(Double.toString(sumVipMonth));

        sumDiamondMonth = monthDiamondPrice;
        BigDecimal a3 = new BigDecimal(Double.toString(sumDiamondMonth));

        sumAllMonth = a1.add(a2).add(a3).doubleValue();

        map.put("sumTicketMonth", sumTicketMonth);
        map.put("sumVipMonth", sumVipMonth);
        map.put("sumDiamondMonth", sumDiamondMonth);
        map.put("sumAllMonth", sumAllMonth);


        //总门票
        List<VipOrder> allTickets = afterVipOrderService.getVipOrderTicketV2(allParam);
        Double allTicketPrice = allTickets.stream().filter(Objects::nonNull).mapToDouble(e -> Double.parseDouble(e.getPrice().stripTrailingZeros().toPlainString())).sum();


        //总vip
        List<VipOrder> allVips = afterVipOrderService.getVipOrderV2(allParam);
        Double allVipPrice = allVips.stream().filter(Objects::nonNull).mapToDouble(e -> Double.parseDouble(e.getPrice().stripTrailingZeros().toPlainString())).sum();

        //钻石
        List<AppOrder> allAppOrder = afterOrderService.getAppOrderV2(allParam);
        Double allAppOrderMoney = allAppOrder.stream().filter(Objects::nonNull).mapToDouble(e -> Double.parseDouble(e.getMoney().stripTrailingZeros().toPlainString())).sum();

        //总:门票:  VIP: 钻石:  总:

        Double sumTicketAll = 0d;
        Double sumVipAll = 0d;
        Double sumDiamondAll = 0d;
        Double sumAllAll = 0d;

        sumTicketAll = allTicketPrice;
        BigDecimal d1 = new BigDecimal(Double.toString(sumTicketAll));

        sumVipAll = allVipPrice;
        BigDecimal d2 = new BigDecimal(Double.toString(sumVipAll));

        sumDiamondAll = allAppOrderMoney;
        BigDecimal d3 = new BigDecimal(Double.toString(sumDiamondAll));

        sumAllAll = d1.add(d2).add(d3).doubleValue();

        map.put("sumTicketAll", sumTicketAll);
        map.put("sumVipAll", sumVipAll);
        map.put("sumDiamondAll", sumDiamondAll);
        map.put("sumDiamondAll", sumDiamondAll);
        map.put("sumAllAll", sumAllAll);


        Integer activeNum = 0;
        //日活跃人数
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        String format = formatter.format(new Date());
        if (ObjectUtil.isEmpty(time) || time.equals(format)) {
            Set<String> keys = redisUtil.keys(RedisKeys.active + "*");
            activeNum = keys.size();
        } else {
            activeNum = afterAppActiveService.countAppActive(todayParam);
        }
        map.put("activeNum", activeNum);


        Integer todayRegisterUsers = 0;
        //今日注册会员数
        List<AppUser> appUsers1 = appUserService.userCount(todayParam);
        todayRegisterUsers = appUsers1.size();
        map.put("todayRegisterUsers", todayRegisterUsers);


        Integer users = 0;
        //会员总注册数
        List<AppUser> appUsers = appUserService.userCount(new HashMap<>());
        users = appUsers.size();

        map.put("users", users);

        request.setAttribute("time", time);
        return map;
    }


    public Map<String, Object> indexData(String time) {

        System.out.println("参数" + time);


        Map<String, Object> map = new HashMap<>();


        //今日钻石充值金额
        Double todayChongzhi = 0d;

        //钻石充值总金额
        Double chongzhi = 0d;

        //今日会员充值金额
        Double todayVip = 0d;

        //今日门票金额
        Double todayMengPiao = 0d;

        //会员充值总金额
        Double todayVipAll = 0d;

        //今日门票总金额
        Double todayMengPiaoAll = 0d;

        //日活跃人数
        Integer activeNum = 0;

        //今日注册会员数
        Integer todayRegisterUsers = 0;

        //会员总注册数
        Integer users = 0;

        //会员+钻石充值总金额
        Double vipandchongzhi = 0d;

        //当前钻石总余额
        Double diamondsAll = 0d;

        //当前金币总余额
        Double jinbi = 0d;

        //今日礼物订单总数
        Integer gift = 0;

        //礼物订单总金额
        Double giftAmount = 0d;

        //今日礼物订单总金额
        Double todayGiftAmount = 0d;

        //门票+会员+钻石
        Double mhzChongzhi = 0d;


        //Map
        Map<String, Object> params;

        Map<String, Object> allparams;


        params = new HashMap<>();

        if (ObjectUtil.isNotEmpty(time)) {

            params.put("today", time);
        } else {
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
            String format = formatter.format(new Date());
            params.put("today", format);
        }

        allparams = new HashMap<>();

        if (ObjectUtil.isNotEmpty(time)) {
            String hms = " 23:59:59";
            String allTime = time + hms;
            allparams.put("alltoday", allTime);
        } else {
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String format = formatter.format(new Date());
            allparams.put("alltoday", format);
        }

        //vip订单表
        List<VipOrder> vipOrders = afterVipOrderService.list(params);

        List<VipOrder> vipOrderAll = new ArrayList<>();
        //取出所有设备号不为空的参数
        for (int i = 0; i < vipOrders.size(); i++) {
            VipOrder vipOrder = vipOrders.get(i);
            if (ObjectUtil.isNotEmpty(vipOrder.getMobileSpec())) {
                vipOrderAll.add(vipOrder);
            }
        }
        //总数
        int allPaySize = vipOrderAll.size();
        int iPhone = 0;
        //统计苹果
        for (int i = 0; i < vipOrderAll.size(); i++) {
            VipOrder vipOrder = vipOrderAll.get(i);
            if (vipOrder.getMobileSpec().equals("iPhone")) {
                iPhone++;
            }
        }
        //安卓
        int android = allPaySize - iPhone;

        String proportion = "安卓：" + android + " 苹果：" + iPhone;


        //今日钻石充值金额
        todayChongzhi = afterOrderService.total(params);
        //钻石充值总金额
        chongzhi = afterOrderService.total(allparams);


        //今日会员充值金额
        todayVip = afterVipOrderService.total(params);

        //门票
        todayMengPiao = afterVipOrderService.todayMengPiao(params);


        //会员充值总金额
        todayVipAll = afterVipOrderService.total(allparams);


        //门票总数
        todayMengPiaoAll = afterVipOrderService.todayMengPiao(allparams);


        //日活跃人数
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        String format = formatter.format(new Date());
        if (ObjectUtil.isEmpty(time) || time.equals(format)) {
            Set<String> keys = redisUtil.keys(RedisKeys.active + "*");
            activeNum = keys.size();
        } else {
            activeNum = afterAppActiveService.countAppActive(params);
        }


        //今日注册会员数
        List<AppUser> appUsers1 = appUserService.userCount(params);
        todayRegisterUsers = appUsers1.size();


        //会员总注册数
        List<AppUser> appUsers = appUserService.userCount(new HashMap<>());
        users = appUsers.size();


        //会员+钻石充值总金额
        BigDecimal d1 = new BigDecimal(Double.toString(todayVipAll));
        BigDecimal d2 = new BigDecimal(Double.toString(chongzhi));
        vipandchongzhi = d1.add(d2).doubleValue();


        //当前钻石总余额
        diamondsAll = appUsers.stream().mapToDouble(e -> Double.valueOf(e.getDiamonds().stripTrailingZeros().toPlainString())).sum();
        diamondsAll = formatDouble(diamondsAll);


        //当前金币总余额
        jinbi = appUsers.stream().mapToDouble(e -> Double.valueOf(e.getJinbi().stripTrailingZeros().toPlainString())).sum();
        jinbi = formatDouble(jinbi);

        //今日礼物订单总数
        params = new HashMap<>();
        params.put("today", "1");
        List<AppGiftReward> todayGift = appGiftRewardService.list(params);
        gift = todayGift.size();

        //礼物订单总金额
        List<AppGiftReward> list = appGiftRewardService.list(new HashMap<>());
        giftAmount = list.stream().mapToDouble(e -> e.getMoney()).sum();
        giftAmount = formatDouble(giftAmount);


        //今日礼物订单总金额
        todayGiftAmount = todayGift.stream().mapToDouble(e -> e.getMoney()).sum();
        todayGiftAmount = formatDouble(todayGiftAmount);


        //门票+会员+钻石
        BigDecimal p1 = new BigDecimal(Double.toString(todayVipAll));
        BigDecimal p2 = new BigDecimal(Double.toString(chongzhi));
        BigDecimal p3 = new BigDecimal(Double.toString(todayMengPiaoAll));
        mhzChongzhi = p1.add(p2).add(p3).doubleValue();


        map.put("proportion", proportion);//充值比例

        map.put("todayChongzhi", todayChongzhi);//今日钻石充值金额

        map.put("chongzhi", chongzhi);//钻石充值总金额

        map.put("todayVip", todayVip);//今日会员充值金额
        map.put("todayMengPiao", todayMengPiao);//今日会员充值金额

        map.put("todayVipAll", todayVipAll);//会员充值总金额
        map.put("todayMengPiaoAll", todayMengPiaoAll);//会员充值总金额

        map.put("activeToday", activeNum);//日活跃人数

        map.put("todayRegisterUsers", todayRegisterUsers);//今日注册会员数

        map.put("users", users);//会员总注册数

        map.put("vipandchongzhi", vipandchongzhi);//会员+钻石充值总金额

        map.put("diamondsAll", diamondsAll);//当前钻石总余额

        map.put("jinbi", jinbi);//当前金币总余额

        map.put("gift", gift);  // 今日礼物订单总数

        map.put("giftAmount", giftAmount);//礼物订单总金额

        map.put("todayGiftAmount", todayGiftAmount);//今日礼物订单总金额
        map.put("mhzChongzhi", mhzChongzhi);//今日礼物订单总金额

        request.setAttribute("time", time);
        return map;


    }


    public Map<String, Object> indexDataGongHui(String time, User user) {

        //获取工会底下的人员
        String invitationCode = user.getCode();
        //查询用户表底下关联的用户取出id
        List<AppUser> appUsers = appUserService.getInvitationCode(invitationCode);

        List<String> list = new ArrayList<>();

        appUsers.forEach(e -> {

            list.add(String.valueOf(e.getId()));
        });
        String join = String.join(",", list);

        //数据组装
        Map<String, Object> map = new HashMap<>();

        //礼物收入
        Double giftPrice = 0d;
        //礼物总收入
        Double giftAllPrice = 0d;
        //音视频收入
        Double audioVideoPrice = 0d;
        //音视频总收入
        Double audioVideoAllPrice = 0d;

        if (ObjectUtil.isNotEmpty(list) && list.size() > 0) {
            //Map
            Map<String, Object> params;  //自定义时间

            Map<String, Object> allParams; //全部时间

            params = new HashMap<>();

            if (ObjectUtil.isNotEmpty(time)) {

                params.put("today", time);
                params.put("userids", join);
                params.put("leixing", 1);
            } else {
                SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
                String format = formatter.format(new Date());
                params.put("today", format);
                params.put("userids", join);
                params.put("leixing", 1);
            }

            allParams = new HashMap<>();

            if (ObjectUtil.isNotEmpty(time)) {
                String hms = " 23:59:59";
                String allTime = time + hms;
                allParams.put("alltoday", allTime);
                allParams.put("userids", join);
                allParams.put("leixing", 1);
            } else {
                SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                String format = formatter.format(new Date());
                allParams.put("alltoday", format);
                allParams.put("userids", join);
                allParams.put("leixing", 1);
            }


            //
            List<AppMingxiJinbi> appMingxiJinbis = appMingxiJinbiService.indexCount(params);

            List<AppMingxiJinbi> appMingxiJinbiAlls = appMingxiJinbiService.indexCount(allParams);

            //计算今日礼物收入
            List<AppMingxiJinbi> gift = new ArrayList<>();
            appMingxiJinbis.forEach(e -> {
                boolean b = e.getBeizhu().equals("礼物收入");
                if (b) {
                    gift.add(e);
                }
            });

            giftPrice = gift.stream().mapToDouble(e -> Double.valueOf(e.getNum().stripTrailingZeros().toPlainString())).sum();

            //计算礼物总收入
            List<AppMingxiJinbi> giftAll = new ArrayList<>();
            appMingxiJinbiAlls.forEach(e -> {
                boolean b = e.getBeizhu().equals("礼物收入");
                if (b) {
                    giftAll.add(e);
                }
            });
            giftAllPrice = giftAll.stream().mapToDouble(e -> Double.valueOf(e.getNum().stripTrailingZeros().toPlainString())).sum();

            //计算今日礼物收入
            List<AppMingxiJinbi> audioVideoPrices = new ArrayList<>();
            appMingxiJinbis.forEach(e -> {
                boolean b = e.getBeizhu().equals("语音消息收入");
                if (b) {
                    gift.add(e);
                }
                boolean b1 = e.getBeizhu().equals("视频消息收入");
                if (b1) {
                    gift.add(e);
                }
            });

            audioVideoPrice = audioVideoPrices.stream().mapToDouble(e -> Double.valueOf(e.getNum().stripTrailingZeros().toPlainString())).sum();

            //计算礼物总收入
            List<AppMingxiJinbi> audioVideoAllPrices = new ArrayList<>();
            appMingxiJinbiAlls.forEach(e -> {
                boolean b = e.getBeizhu().equals("语音消息收入");
                if (b) {
                    gift.add(e);
                }
                boolean b1 = e.getBeizhu().equals("视频消息收入");
                if (b1) {
                    gift.add(e);
                }
            });
            audioVideoAllPrice = audioVideoAllPrices.stream().mapToDouble(e -> Double.valueOf(e.getNum().stripTrailingZeros().toPlainString())).sum();

        }


        map.put("giftPrice", giftPrice);//礼物收入
        map.put("giftAllPrice", giftAllPrice);//礼物总收入
        map.put("audioVideoPrice", audioVideoPrice);//音视频收入
        map.put("audioVideoAllPrice", audioVideoAllPrice);//音视频总收入


//        //收到礼物
//        List<AppMingXiShouLi> appMingXiShouLis = appMingXiShouLiService.listAfter(params);
//        giftPrice = appMingXiShouLis.stream().mapToDouble(e -> Double.valueOf(e.getFujianum().stripTrailingZeros().toPlainString())).sum();
//
//
//        //收到礼物总数
//        List<AppMingXiShouLi> appMingXiShouLiAlls = appMingXiShouLiService.listAfter(allParams);
//        giftAllPrice = appMingXiShouLiAlls.stream().mapToDouble(e -> Double.valueOf(e.getFujianum().stripTrailingZeros().toPlainString())).sum();
//
//
//        //收到钻石
//        params.put("leixing",1);
//        List<AppMingXiZuanShi> appMingXiZuanShis = appMingXiZuanShiService.listAfter(params);
//        diamondNum = appMingXiZuanShis.stream().mapToDouble(e -> Double.valueOf(e.getNum().stripTrailingZeros().toPlainString())).sum();
//        //收到钻石总数
//        allParams.put("leixing",1);
//        List<AppMingXiZuanShi> appMingXiZuanShiAlls = appMingXiZuanShiService.listAfter(allParams);
//        diamondAllNum = appMingXiZuanShiAlls.stream().mapToDouble(e -> Double.valueOf(e.getNum().stripTrailingZeros().toPlainString())).sum();
//
//
//
//
//
//
//        //收到钻石
//        params.put("leixing",2);
//        List<AppMingXiZuanShi> appMingXiZuanShisConsume = appMingXiZuanShiService.listAfter(params);
//        diamondNumConsume = appMingXiZuanShisConsume.stream().mapToDouble(e -> Double.valueOf(e.getNum().stripTrailingZeros().toPlainString())).sum();
//        //收到钻石总数
//        allParams.put("leixing",2);
//        List<AppMingXiZuanShi> appMingXiZuanShiAllsConsume = appMingXiZuanShiService.listAfter(allParams);
//        diamondAllNumConsume = appMingXiZuanShiAllsConsume.stream().mapToDouble(e -> Double.valueOf(e.getNum().stripTrailingZeros().toPlainString())).sum();
//
//
//
//        map.put("giftPrice", giftPrice);//礼物
//        map.put("giftAllPrice", giftAllPrice);//礼物总数
//        map.put("diamondNum", diamondNum);//钻石
//        map.put("diamondAllNum", diamondAllNum);//钻石总数
//
//
//        map.put("giftNumConsume", giftNumConsume);//消费礼物
//        map.put("giftAllNumConsume", giftAllNumConsume);//消费礼物总数
//        map.put("diamondNumConsume", diamondNumConsume);//消费钻石
//        map.put("diamondAllNumConsume", diamondAllNumConsume);//消费钻石总数

        request.setAttribute("time", time);
        return map;
    }


    public static Double formatDouble(double d) {
        return (double) Math.round(d * 100) / 100;
    }

}
